package com.example.my12306;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {
    Button btnContact = null;
    Button btnAccount = null;
    Button btnPassword = null;
    Button btnLogout = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Log.d("My12306", "---onCreate---");
        btnContact = (Button) findViewById(R.id.btnContact);
        btnAccount = (Button) findViewById(R.id.btnAccount);
        btnPassword = (Button) findViewById(R.id.btnPassword);
        btnLogout = (Button) findViewById(R.id.btnLogout);

        MyButtonListener listener = new MyButtonListener();
        btnContact.setOnClickListener(listener);
        btnAccount.setOnClickListener(listener);
        btnPassword.setOnClickListener(listener);
        btnLogout.setOnClickListener(listener);


    }

    class MyButtonListener implements View.OnClickListener {


        @Override
        public void onClick(View v) {

            Intent intent = new Intent();
            switch (v.getId()) {
                case R.id.btnContact:
                    intent.setClass(MainActivity.this, MyContactActivity.class);
                    startActivity(intent);
                    break;
                case R.id.btnAccount:
                    intent.setClass(MainActivity.this, MyAccountActivity.class);
                    startActivity(intent);
                    break;
                case R.id.btnPassword:
                    intent.setClass(MainActivity.this, MyPasswordActivity.class);
                    startActivity(intent);
                    break;
                case R.id.btnLogout:
                    intent.setClass(MainActivity.this, LoginActivity.class);
                    startActivity(intent);
                    finish();
                    break;
            }
        }
    }

    protected void onStart() {


        super.onStart();

        Log.d("My12306","---onStart");
    }

    protected void onRestart() {

        super.onRestart();
        Log.d("My12306","---onRestart---");
    }
}






